import store from '@/store'
import { isArray } from '@/utils/validate'

export function hasAccess(value) {
  if (isArray(value)) {
    // console.log(value)
    let r = value.find((f) => {
      return f == store.state.user.token.utype
    })
    return r
  } else {
    return true
  }
}

export function can(roleOrAbility, value) {
  console.log(roleOrAbility, value, 'roleOrAbility, value')
  let hasRole = false
  const { role, mode } = value
  if (role && mode) {
    if (mode === 'allOf')
      hasRole = role.every((item) => roleOrAbility.includes(item))
    if (mode === 'oneOf')
      hasRole = role.some((item) => roleOrAbility.includes(item))
    if (mode === 'except')
      hasRole = !role.some((item) => roleOrAbility.includes(item))
  }
  return hasRole
}
